﻿CREATE PROCEDURE [dbo].[message_insert]
   @dateOfRead datetime2 = NULL,
   @dateOfSend datetime2,
   @message nvarchar(max),
   @recipientId int,
   @senderId int
AS
INSERT INTO [dbo].[Messages]
(
    DateOfRead,
    DateOfSend,
    Message,
    RecipientId,
    SenderId
)
VALUES
(
    @dateOfRead,
    @dateOfSend,
    @message,
    @recipientId,
    @senderId
)
declare @messageId int = @@IDENTITY

SELECT 
    [MessageId],
    [DateOfRead],
    [DateOfSend],
    [Message],
    [RecipientId],
    [SenderId]
FROM [dbo].[Messages]
WHERE
    Messages.[MessageId] = @messageId
RETURN 0
